{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 如果运行安装 docx2pdf 出现错误：No module named 'pywin32_bootstrap'\n",
    "# 删除下面的注释，运行安装 pywin32==225后，再运行安装 docx2pdf\n",
    "# !pip install pywin32==225"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Anaconda 默认不包含 docx2pdf，需要执行以下脚本进行安装\n",
    "# 如果运行安装出现错误：No module named 'pywin32_bootstrap'，则运行安装 pywin32==225（见上一步）\n",
    "!pip install -i https://mirrors.aliyun.com/pypi/simple/ docx2pdf --user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入工具包 convert(Word -> PDF 转换器)\n",
    "from docx2pdf import convert"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Word文档 文件路径（该文件必须存在）\n",
    "word_file = r'./files/word文档.docx'\n",
    "# 转换后的 PDF文档 文件路径（文件不存在）\n",
    "pdf_file = r'./files/PDF文档.pdf'\n",
    "\n",
    "# 将 Word文件 转换为 PDF文件\n",
    "convert(word_file, pdf_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
